// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:junyeyishu/ui/home/widgets/QGTypeSwitchWidget.dart';
import 'package:junyeyishu/ui/mine/widget/QGMineTradeOrderCell.dart';

import 'widget/QGMineOrderCell.dart';
import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGListState.dart';
import 'package:junyeyishu/widgets/QGNavigationBar.dart';

class QGMineOrderPage extends StatefulWidget {
  const QGMineOrderPage({super.key});
  @override
  State<QGMineOrderPage> createState() => QGMineOrderPageState();
}

class QGMineOrderPageState extends QGListState<QGMineOrderPage> {
  int type = 0;
  var items = ["已买入", "待支付", "进行中", "已取消", "已售出"];
  var title = "寄售订单";
  var myBought_url = url_market_orderList;
  @override
  void initState() {
    super.initState();

    listURL = myBought_url;
    listKey = "list";
    onRefresh();
  }

  @override
  listParam() {
// type_id
// 1已买到、2待付款、3已取消、4发放中、全部
// 1已卖出、2支付中、全部

// items: ["已买入", "待支付", "进行中(上架列表)", "已取消", "已售出"],

    switch (type) {
      case 0:
        return {"tab_id": 1};
      case 1:
        return {"tab_id": 2};
      case 2:
        return {"tab_id": 3};
      case 3:
        return {"tab_id": 4};
      case 4:
        return {"tab_id": 5};
      default:
        break;
    }

    return {};
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Color(0xFFF8F8F6),
        body: Column(
          children: [
            buildHeader(),
            buildList(),
          ],
        ));
  }

  buildHeader() {
    return Container(
      color: Color(0xFFFFFFFF),
      child: Column(children: [
        QGNavigationBar(title: title),
        Container(height: 0.5.rpx, color: Color(0xFFEAEAEA)),
        SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: QGTypeSwitchWidget(
              current: type,
              items: items,
              underline: true,
              fontSize: 13,
              maxFontSize: 14,
              onSwitch: onSwitch),
        ),
        SizedBox(height: 5.rpx),
      ]),
    );
  }

  @override
  itemBuilder(context, index, data) {
    data ??= {};
    data["status"] = type;
    data["tab"] = 1;

    return GestureDetector(
        onTap: () {
          Navigator.of(context)
              .pushNamed(PageMyOrderDetail, arguments: data)
              .then((value) {
            onRefresh();
          });
        },
        child: QGMineTradeOrderCell(data: data));
  }

  onSwitch(index) {
    type = index;
    list = null;

    setState(() {});
    onRefresh();
  }
}
